<template>
  <div>
    <el-row>
      <el-col style="margin-top: 10px">
        当前异常状态：
        <el-select
          v-model="type"
          placeholder="选择异常"
          size="large"
          style="width: 240px"
          @change="change"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-table
          class="box-table"
          :data="Data"
          :stripe="true"
          :border="true"
          :fit="true"
          style="margin-top: 30px"
        >
          <el-table-column
            prop="userName"
            label="病患姓名"
            width="auto"
            align="center"
            header-align="center"
          >
          </el-table-column>
          <el-table-column
            prop="time"
            label="时间"
            width="auto"
            align="center"
            header-align="center"
          >
          </el-table-column>
           <el-table-column
            prop="content"
            label="异常数值"
            width="auto"
            align="center"
            header-align="center"
          >
          <template #default="scope">
          <p style="color:red">{{  scope.row.content}}</p>
          </template>
          </el-table-column>

          <!-- <el-table-column
            fixed="right"
            label="操作"
            align="center"
            width="auto"
          >
            <template #default="scope">
              <el-button
                link
                type="primary"
                size="small"
                @click="
                  info(scope.row);
                  dialogVisible = true;
                "
                >详情</el-button
              >
            </template>
          </el-table-column> -->
        </el-table>
      </el-col>
      <el-col style="margin: 0 auto">
        <el-card>
          <div class="block">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="pageSize"
              :total="Total"
            >
            </el-pagination>
          </div>
        </el-card>
      </el-col>

      <el-dialog
        v-model="dialogVisible"
        title="往期记录"
        width="50%"
        :before-close="handleClose"
      >
        <el-table
          class="box-table"
          :data="msg_info"
          :stripe="true"
          :border="true"
          :fit="true"
        >
          <el-table-column
            prop="problem"
            label="时间"
            width="auto"
            align="center"
            header-align="center"
          >
          </el-table-column>
          <el-table-column
            prop="answer"
            label="心率"
            width="auto"
            align="center"
            header-align="center"
          >
          </el-table-column>
        </el-table>
      </el-dialog>
    </el-row>
  </div>
</template>
<script lang="ts" setup>
import { ref, reactive, toRaw, onMounted, onBeforeMount } from "vue";
import apiService from "@/services/apiService";
import { conversionUtcDate, base64ToExcelAndDownload } from "@/utils/auth";
import { ElMessageBox } from "element-plus";
import { PagingWarningNoticeForAllUsers } from "@/api/api";
import { getToken } from "@/utils/auth";

defineOptions({
  // name 作为一种规范最好必须写上并且和路由的name保持一致
  name: "Yichangjingbao"
});

const type = ref<any>("");
const options = [
  {
    value: "0",
    label: "心率"
  },
  {
    value: "1",
    label: "步数"
  },
  {
    value: "2",
    label: "电子围栏"
  }
];
//选择变化
const change = e => {
  type.value = e;
  GetList();
};
//表格数据
const Data = ref<any>([]);
const currentPage = ref(1); // 当前页数
const pageSize = ref(10); // 每页条数
const Total = ref<number>(1); //总条数

//获取表单数据
const GetList = () => {
  Data.value = [];
  const data = ref({
    token: getToken().accessToken,
    body: {
      pageNumber: currentPage.value,
      pageSize: pageSize.value,
      type: type.value
    }
  });
  PagingWarningNoticeForAllUsers(data.value)
    .then((res: any) => {
      console.log("表单数据", res);
      Data.value.push(...res.data.informs);
      Total.value = res.data.totalRecords;
    })
    .catch((err: any) => {
      console.log(err);
    });
};

//详情数据
const msg_info = ref<any>([]);
const info = row => {};

// 监听页码变化
const handleCurrentChange = val => {
  currentPage.value = val;
  GetList();
};

// 监听每页条数变化
const handleSizeChange = val => {
  pageSize.value = val;
};

const dialogVisible = ref(false);

const handleClose = (done: () => void) => {
  // ElMessageBox.confirm("确认关闭?")
  //   .then(() => {
  done();
  // })
  // .catch(() => {
  //   // catch error
  // });
};
onBeforeMount(() => {
  // GetList();
});
onMounted(() => {
  type.value = "0";
  GetList();
});
</script>

<style lang="scss" scoped></style>
